package com.yanfan.energy.service.impl;

import cn.hutool.core.util.StrUtil;
import com.yanfan.common.core.domain.AjaxResult;
import com.yanfan.energy.domain.TemplateEnergy;
import com.yanfan.energy.mapper.TemplateEnergyDao;
import com.yanfan.energy.service.EnergyTemplateService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author caijinkang
 * @date 2022年10月19日 19:23
 */
@Service("EnergyTemplateService")
public class EnergyTemplateServiceImpl implements EnergyTemplateService {
    @Resource
    private TemplateEnergyDao templateEnergyDao;

    @Override
    public AjaxResult findEnergyTemplate(int currPage, int pageSize, String name, String number, Integer type, Integer grade) {
        PageHelper.startPage(currPage, pageSize);
        if (!StrUtil.isBlank(name)) {
            name = "%" + name + "%";
        }
        if (!StrUtil.isBlank(number)) {
            number = "%" + number + "%";
        }
        List<TemplateEnergy> result = templateEnergyDao.findEnergyTemplate(name, number, type, grade);
        if (result != null && result.size() > 0) {
            return AjaxResult.success(new PageInfo<>(result));
        }
        return AjaxResult.error("查询失败");
    }

    @Override
    public List<TemplateEnergy> findTemplateEnergy(int currPage, int pageSize) {
        return templateEnergyDao.queryBycCurr(currPage, pageSize);
    }
}
